//
//  CustomizeView.m
//  timelyRain
//
//  Created by Jiafei Wei on 16/10/11.
//  Copyright © 2016年 Jiafei Wei. All rights reserved.
//

#import "CustomizeView.h"
#import "MBTPre.h"
@interface CustomizeView()
@property (weak, nonatomic) IBOutlet UITextField *input;
- (IBAction)ok:(id)sender;
@property (weak, nonatomic) IBOutlet UIView *content;

- (IBAction)cancle:(id)sender;
@end
@implementation CustomizeView
+ (instancetype)headerView
{
    CustomizeView *footer = [[[NSBundle mainBundle] loadNibNamed:@"CustomizeView" owner:nil options:nil] lastObject];
    CGRect frame = footer.frame;
    frame.size.width=SCREEN_W;
    frame.size.height=SCREEN_H;//重新设定
    footer.frame =frame;
    footer.content.layer.masksToBounds = YES;
    footer.content.layer.cornerRadius = 10;
    //监听键盘事件
    [[NSNotificationCenter defaultCenter] addObserver:footer selector:@selector(willShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:footer selector:@selector(willHide) name:UIKeyboardWillHideNotification object:nil];
    return footer;
}

/**
 *  键盘弹出
 *
 */
-(void)willShow:(NSNotification *)notifi{
    NSLog(@"willShow===%@",notifi.userInfo);
    CGFloat maxY = CGRectGetMaxY(_content.frame);//_content.frame.origin.y;
    //2.获取键盘的y值
    CGRect kbEndFrm = [notifi.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    CGFloat kbY = kbEndFrm.origin.y;
    //3.进行比较
    //计算距离
    CGFloat delta = kbY - maxY;
    NSLog(@"delta=======%lf",delta);
    if(delta<0){//需要往上移
        //添加个动画
        [UIView animateWithDuration:0.25 animations:^{
            self.transform = CGAffineTransformMakeTranslation(0, delta);
        }];
    }
}
/**
 *  隐藏键盘
 */
-(void)willHide{
    NSLog(@"willHide");
    /*
     * 恢复原状
     */
    [UIView animateWithDuration:0.25 animations:^{
        self.transform = CGAffineTransformIdentity;
    }];
}

- (IBAction)ok:(id)sender{
    
}
- (IBAction)cancle:(id)sender {
    
}
@end
